package com.lemt.mall.controller;

import com.lemt.common.mapper.AddressMapper;
import com.lemt.common.result.Res;
import com.lemt.mall.entity.vo.OrderVo;
import com.lemt.mall.service.IOrdersService;
import com.sun.org.apache.xpath.internal.operations.Bool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.Data;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zik
 * @since 2023-09-10
 */
@Api(tags = "订单管理")
@RestController
@RequestMapping("/mall/orders")
public class OrdersController {

    @Resource(name = "OrdersService")
    private IOrdersService ordersService;

    @ApiOperation("生成订单")
    @PostMapping("/adaOrder")
    public Res<Boolean> addOrder(@RequestBody OrderVo orderVo){
        if (ordersService.addOrder(orderVo)){
            return Res.ok(true);
        }
        return Res.fail(false);
    }

    @ApiOperation("取消订单")
    @DeleteMapping("/remove/{orderNum}")
    public Res<Boolean> removeOrder(@PathVariable String orderNum){
        return Res.ok(ordersService.removeOrder(orderNum));

    }

    @ApiOperation("获取订单")
    @GetMapping("/getOrder/{id}")
    public Res<List<OrderVo>> getOrder(@PathVariable Integer id){
        List<OrderVo> order = ordersService.getOrder(id);
        return Res.ok(order);
    }






}
